package com.example.socdok;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class ScoreState implements IState {

	Bitmap up;
	Bitmap down;
	Bitmap backG;
	Bitmap retry;
	Bitmap toMain;
	SurfaceHolder stateholder;
	int count,i=0,alpha=0;
	int x;
	int y;
	@Override
	public void Init(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
		up = AppManager.getInstance().getBitmap(R.drawable.up);
		down = AppManager.getInstance().getBitmap(R.drawable.up);
		backG = AppManager.getInstance().getBitmap(R.drawable.background3);
		retry = AppManager.getInstance().getBitmap(R.drawable.retry);
		toMain = AppManager.getInstance().getBitmap(R.drawable.tomain);
		
	}

	@Override
	public void Destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Update() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Render(Canvas canvas) {
		y = canvas.getHeight();
		x = canvas.getWidth();
		
			canvas.drawBitmap(backG,0 - i,0, null);
			canvas.drawBitmap(retry, (x/5)*2, y/2, null);
			canvas.drawBitmap(toMain, (x/5)*4, y/2, null);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		AppManager.getInstance().getGameView().ChangeGameState(new CreditState());
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		int action = event.getAction();
		
		int m_x, m_y;
		m_x = (int) event.getX();
		m_y = (int) event.getY();
		
		Rect rt = new Rect();
		
		if(event.getAction() == MotionEvent.ACTION_DOWN){
			rt.set((x/5)*2, y/2, (x/5)*2 + retry.getWidth(), y/2 + retry.getHeight());
			if(rt.contains(m_x, m_y)){
				AppManager.getInstance().getGameView().ChangeGameState(new PlayGameState());
			}
		
			rt.set((x/5)*4, y/2, (x/5)*4 + toMain.getWidth(), y/2 + toMain.getHeight());
			if(rt.contains(m_x, m_y)){
				AppManager.getInstance().getGameView().ChangeGameState(new IntroState());
			}
			
		}
		return true;
	}

	@Override
	public void Init() {
		// TODO Auto-generated method stub
		
	}

}

